<?php
namespace app\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use app\modules\v1\models\Log;
use yii\web\NotFoundHttpException;
use app\modules\v1\models\Userdetail;
use app\modules\v1\models\Userfile;

class UserRemixInfoController extends ActiveController{
    
    public function actions() {
        $actions = parent::actions();
        unset($actions['index'], $actions['view'], $actions['create'], $actions['update'], $actions['delete']);
    }
    
    public $modelClass = '';
    
    public function actionIndex(){
        return new NotFoundHttpException(404);
    }
    
    public function actionView($id){
        $this->log('GET', json_encode(['ID' => $id]));
        $infoModel = new Userdetail();
        $fileModel = new Userfile();
        return [$infoModel->findOne($id), $fileModel->findOne($id)];
    }
    
    protected function log($op,$data){
        
        $log = new Log();
        
        $log->attributes = ['operation' => $op,'class' => 'UserRemix','requestData' => $data,'dateTime' => date('Y-m-d H:i:s'),'ip' => Yii::$app->request->userIP];
        
        if(!$log->save()){
            return $log->getFirstError();
        }
        
    }
    
}